package com.itheima;

import java.security.SecureRandom;

public class Java_05 {
    public static void main(String[] args) {
        //案例练习：数字加密，完成数字加密程序的开发
        System.out.println("加密后的结果是：" +encrypt(8346));
    }

    //密码加密方法
    public static String encrypt(int number){
        //把这个密码拆分成一个一个的数字才可以对它进行加密啊
        int[] numbers = split(number);
        for (int i = 0; i < numbers.length; i++) {
            numbers[i] = (numbers[i] + 5) % 10;
        }
        reserve(numbers);
        String data = "";
        for (int i = 0; i < numbers.length; i++) {
            data += numbers[i];
        }
        return data;
    }

    //密码拆分方法
    public static int[] split(int number){
        //number = 1983
        int[] numbers = new int[4];
        numbers[0] = number / 1000;
        numbers[1] = (number / 100) % 10;
        numbers[2] = (number / 10) % 10;
        numbers[3] = number % 10;
        return numbers;
    }

    //数组反转方法
    public static void reserve(int[] numbers){
        for (int i = 0,j = numbers.length-1; i < j; i++,j--) {
            //数组交换
            int temp = numbers[j];
            numbers[j] = numbers[i];
            numbers[i] = temp;
        }

    }
    }

